package com.emep.changzhi.analyse.service.information;

import com.emep.changzhi.analyse.entity.information.DataMessageRecordWarning;
import com.emep.changzhi.analyse.repository.information.DataMessageRecordWarningRepository;
import com.emep.changzhi.analyse.utils.MapUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.List;
import java.util.Map;

/**
 * @author Wangcc
 * @version V1.0
 * @Description: 消息推送记录
 * @date 2018/2/27 17:24
 */
@Slf4j
@Service
public class DataMessageRecordWarningService {


    @Resource
    private DataMessageRecordWarningRepository dataMessageRecordWarningRepository;




    /**
     *
     * 新增消息推送记录
     *
     * @param payload
     * @return
     * @throws Exception
     */
    public DataMessageRecordWarning save(Map<String, Object> payload) {
        DataMessageRecordWarning DataMessageRecordWarning = null;
        try {
            DataMessageRecordWarning DataMessageRecordWarning1 = (DataMessageRecordWarning) MapUtils.convertMap(DataMessageRecordWarning.class,payload);
            DataMessageRecordWarning = dataMessageRecordWarningRepository.save(DataMessageRecordWarning1);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return DataMessageRecordWarning;
    }
    /**
     * @author xy
     * @Description: 首页
     * @date 2018/3/8 10:11
     * @version V1.0
     */
    public List<DataMessageRecordWarning> findDataMessageRecordWarningByHome(Integer pageSize){
        List<DataMessageRecordWarning> dataMessageRecordWarnings = null;
        try {
            dataMessageRecordWarnings = dataMessageRecordWarningRepository.dataMessageRecordWarningHome(pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataMessageRecordWarnings;

    }
    /**
     * @author xy
     * @Description: 翻页查询
     * @date 2018/3/8 10:18
     * @version V1.0
     */

    public List<DataMessageRecordWarning> findDataMessageRecordWarningByFlip(String id,Integer pageSize) {
        List<DataMessageRecordWarning> dataMessageRecordWarnings = null;
        try {
            dataMessageRecordWarnings = dataMessageRecordWarningRepository.dataMessageRecordWarningFlip(id,pageSize);
        }catch (Exception e){
            log.error(e.getClass().getName()+":"+ e.getMessage());
            log.error(e.getLocalizedMessage());
        }
        return dataMessageRecordWarnings;
    }


}


